/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tuyensinh;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

/**
 *
 * @author user
 */
public class KhuVuc {

    static Connection conn;
    static Statement stm;
    String makhuvuc;
    float diemcong;

    public KhuVuc(String makhuvuc, float diemcong) {
        this.makhuvuc = makhuvuc;
        this.diemcong = diemcong;
    }

    public static void openDatabase() throws SQLException {
        conn = DriverManager.getConnection("jdbc:odbc:tuyensinh");
        stm = conn.createStatement();
    }

    public static void closeDatabase() throws SQLException {
        stm.close();
        conn.close();
    }

    public static ArrayList<String> getDsMaKhuVuc() throws SQLException {
        openDatabase();
        ArrayList<String> result = new ArrayList<>();
        String query = "select * from KhuVuc";
        ResultSet rs = stm.executeQuery(query);
        if (rs.next()) {
            do {
                result.add(rs.getString("makhuvuc"));
            } while (rs.next());
        }
        return result;
    }

    public static float getDiemCongByMaKV(String makv) throws SQLException {
        openDatabase();
        float diemCong = 0;
        String query = "select diemcong from KhuVuc where makhuvuc='" + makv + "'";
        ResultSet rs = stm.executeQuery(query);
        if (rs.next()) {
            diemCong = rs.getFloat("diemcong");
        }
        closeDatabase();
        return diemCong;
    }

    public String getmakuvuc() {
        return makhuvuc;
    }

    public float getdiemcong() {
        return diemcong;
    }

    public void setmakhuvuc(String makhvuc) {
        makhuvuc = makhvuc;
    }

    public void setdiemcong(float dcong) {
        diemcong = dcong;
    }
}
